package com.scsj.supermarket.customview.BalanceChoicePop;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupWindow;

import com.scsj.supermarket.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 余额选择的pop
 */

public class BalanceTypeWindow extends PopupWindow {

    private View mMenuView = null;

    private Context context;
    private ImageView cancelIv;
    private EditText other_resion;
    private Button commitBtn;
    private ListView listView;
    private String resion = "";
    private AAComAdapter<String> adapter;
    private List<String> resionList = new ArrayList<String>();
    private String[] resions = {"全部", "充值", "提现", "消费", "退款","结算","分销"};

    public BalanceTypeWindow(final Context context, final Handler handler) {
        super(context);
        this.context = context;
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mMenuView = inflater.inflate(R.layout.balance_type_window_layout, null);
//        cancelIv = (ImageView) mMenuView.findViewById(R.id.cancel_iv);
//        commitBtn = (Button) mMenuView.findViewById(R.id.commit_btn);
        listView = (ListView) mMenuView.findViewById(R.id.listview);
//        other_resion = (EditText) mMenuView.findViewById(R.id.other_resion);
        for (int i = 0; i < resions.length; i++) {
            resionList.add(resions[i]);
        }
        adapter = new AAComAdapter<String>(context, R.layout.balance_type_resion_item, resionList) {
            @Override
            public void convert(AAViewHolder holder, final String mt) {
                holder.setText(R.id.resion_tv, mt);

                holder.getConvertView().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        resion = mt;
                        handler.sendEmptyMessage(1);
                        dismiss();
                    }
                });
            }
        };
        listView.setAdapter(adapter);
//        other_resion.addTextChangedListener(new TextWatcher() {
//            @Override
//            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//
//            }
//
//            @Override
//            public void onTextChanged(CharSequence s, int start, int before, int count) {
//            }
//
//            @Override
//            public void afterTextChanged(Editable s) {
//                resion = s.toString();
//                adapter.notifyDataSetChanged();
//            }
//        });
//        commitBtn.setOnClickListener(itemsOnClick);
//
//        cancelIv.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                dismiss();
//            }
//        });
        //设置SelectPicPopupWindow的View
        this.setContentView(mMenuView);
        //设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.FILL_PARENT);
        //设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.FILL_PARENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        //设置SelectPicPopupWindow弹出窗体动画效果
//				this.setAnimationStyle(R.style.AnimBottom);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
        //mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
//        mMenuView.setOnTouchListener(new View.OnTouchListener() {
//
//            public boolean onTouch(View v, MotionEvent event) {
//
////						int height = mMenuView.findViewById(R.id.pop_layout).getTop();
////						int y=(int) event.getY();
////						if(event.getAction()==MotionEvent.ACTION_UP){
////							if(y<height){
////								dismiss();
////							}
////						}
//                dismiss();
//                return true;
//            }
//        });

    }


    public String getResion() {
        return resion;
    }
}
